﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp0
{
    public partial class ke1 : Form
    {
         string id;
        public ke1()
        {
            InitializeComponent();
        }
        public ke1(string keid)
        {
            this.id = keid;
            
            InitializeComponent();
            

        }

        private void 商品管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void ke1_Load(object sender, EventArgs e)
        {
            label2.Text = id;
            Table();
        }
        private void Table()
        {
            dataGridView1.Rows.Clear();
            string sql = "select * from Merchandise where Mstate='上架'";
            Dao dao = new Dao();
            IDataReader dr = dao.read(sql);
            while (dr.Read())
            {
                string a, b, c, d, f;
                a = dr["Mid"].ToString();
                b = dr["Mname"].ToString();
                c = dr["Munit"].ToString();
                d = dr["Mnorm"].ToString();
                f = dr["Mprince"].ToString();
             
                string[] str = { a, b, c, d,  f, };
                dataGridView1.Rows.Add(str);
            }
            dr.Close();
        }
        private void name_search()
        {//查名 显示
            dataGridView1.Rows.Clear();
            string sql = $"select * from Merchandise where Mstate='上架' and Mname like'%{textBox2.Text}%'";
            Dao dao = new Dao();
            IDataReader dr = dao.read(sql);
            while (dr.Read())
            {
                string a, b, c, d, f;
                a = dr["Mid"].ToString();
                b = dr["Mname"].ToString();
                c = dr["Munit"].ToString();
                d = dr["Mnorm"].ToString();
                f = dr["Mprince"].ToString();


                string[] str = { a, b, c, d, f, };
                dataGridView1.Rows.Add(str);

            }
            dr.Close();

        }

        private void button5_Click(object sender, EventArgs e)
        {
            name_search();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Table();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                ke1_ren b = new ke1_ren(id);
                b.ShowDialog();
                
            }
            catch
            {
                MessageBox.Show("错误");
            }


        }

        private void button7_Click(object sender, EventArgs e)
        {
            buy a = new buy(dataGridView1.SelectedRows[0].Cells[0].Value.ToString(),id);

            a.ShowDialog();
          
        }
    }
}
